package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.activity.MainActivity;
import com.lanou.sfu.songforu.entity.ArtistListEntity;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/10/24.
 */
public class MusicLibraryArtistAdapter extends PagerAdapter {
    private Context mContext;
    private List<ArtistListEntity.ArtistEntity> lists;
    private MainActivity activity;

    public MusicLibraryArtistAdapter(Context context, List<ArtistListEntity.ArtistEntity> datas){
        lists = datas;
        mContext = context;
        activity = (MainActivity) context;
    }


    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return (view == object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        ImageView imageView = new ImageView(mContext);
        Picasso.with(mContext).load(lists.get(position).getAvatar_big()).placeholder(R.mipmap.music).into(imageView);
        container.addView(imageView);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.transData(lists, position);
            }
        });
        return imageView;

    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager)container).removeView((ImageView)object);
    }
}
